


use Data/event_study_sample_quartsince2006.dta, clear  // postcode data





* additional events:


	** april 2007 SHCP decrease
	** january 2008 1:1 FIT introduced


	gen SHCP_decreasetime = -1*(contract_quarter  - tq(2007, q2))

	gen SFIT_starttime = contract_quarter  - tq(2008, q1)
	
	
gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
 
	* 3 quarters is nine months 
	local length = 3
		 
	forval t = 0(1)`length' {
	* `t' < 0 indicates in low subsidy period relative to the event

		gen event_after`t' = SHCP_decreasetime ==`t'| SFIT_starttime ==`t' | SHCP_end ==`t' |  PFIT_starttime==`t' | PFIT_endtime==`t' | ///
		 SRES1_end ==`t' | SRES2_end==`t' | SRES_TFIT_endtime==`t' | FFIT_endtime==`t'
		 	 
		 gen event_before`t' = SHCP_decreasetime ==-`t'| SFIT_starttime ==-`t' | SHCP_end ==-`t'  | PFIT_starttime==-`t' | PFIT_endtime==-`t' | ///
		 SRES1_end ==-`t' | SRES2_end==-`t' | SRES_TFIT_endtime==-`t' | FFIT_endtime==-`t'
		
		gen event_after_new`t' = event_after`t'*cum
		gen event_before_new`t' = event_before`t'*cum
		
		
			
		drop event_after`t'
		drop event_before`t'
			
		}
		
		
		
		gen increases = (PFIT_starttime <=3 & PFIT_starttime>=-3) | (SFIT_starttime<=3 & SFIT_starttime>=-3)
		
		
				
	
	label variable event_before_new3  "Event Period -3"
	label variable event_before_new2  "Event Period -2"
	label variable event_before_new1  "Event Period -1"
	label variable event_after_new0   "Event Period "
	label variable event_after_new1   "Event Period +1"
	label variable event_after_new2   "Event Period +2"
	label variable event_after_new3   "Event Period +3"


	drop    event_before_new0 
		

		
		
		reghdfe green_p event_before_new3 event_before_new2 event_before_new1  event_after_new0 event_after_new1  event_after_new2 event_after_new3  ///
	     [aweight =NCustomers]   ,  cluster(postcode) absorb(postcode quarter )

	eststo model2c
	
		coefplot (model2c, keep(event_before_new3  event_before_new2  event_before_new1) mcolor(blue) ciopts(lcolor(blue)) msymbol(o)) ///
	 (model2c, keep(event_after_new0 ) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)) ///
	(model2c, keep( event_after_new1 event_after_new2 event_after_new3 ) mcolor(red) ciopts(lcolor(red)) msymbol(o)), vertical ///
	 relocate(event_before_new3 = -2.84 event_before_new2 = -1.84 event_before_new1 = -0.84 event_after_new0 = -0 ///
	event_after_new1 =0.84  event_after_new2=1.84 event_after_new3=2.84 )   legend(off) yline(0) ///
	xtitle("Event time") xlabel(-3(1)3)  xline(0, lcolor(gs10) lpattern(dash) lwidth(vthin)) yscale(range(-0.025 0.025)) ylabel(-0.02(0.01)0.02)  

		
		
				graph export Analysis/Event_from2006.png, replace

		
		
		
		

		
		
		reghdfe green_p i.increases#c.event_before_new3 i.increases#c.event_before_new2 i.increases#c.event_before_new1  i.increases#c.event_after_new0 i.increases#c.event_after_new1  i.increases#c.event_after_new2 i.increases#c.event_after_new3  ///
	     [aweight =NCustomers]   ,  cluster(postcode) absorb(postcode quarter )

	eststo model2c
	
		coefplot (model2c, keep(1.increases#c.event_before_new3 1.increases#c.event_before_new2 1.increases#c.event_before_new1 )  mcolor(blue) ciopts(lcolor(blue)) msymbol(o)) ///
		 (model2c, keep(1.increases#c.event_after_new0 ) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)) ///
	(model2c, keep( 1.increases#c.event_after_new1 1.increases#c.event_after_new2 1.increases#c.event_after_new3 ) mcolor(red) ciopts(lcolor(red)) msymbol(o)), vertical ///
	  relocate(1.increases#c.event_before_new3 = -2.84 1.increases#c.event_before_new2 = -1.84 1.increases#c.event_before_new1 = -0.84 1.increases#c.event_after_new0 = -0 ///
	1.increases#c.event_after_new1 =0.84  1.increases#c.event_after_new2=1.84 1.increases#c.event_after_new3=2.84 )   legend(off) yline(0)  ///
	xtitle("Event time") xlabel(-3(1)3)  xline(0, lcolor(gs10) lpattern(dash) lwidth(vthin)) 

		graph export Analysis/Event_increasesonly.png, replace
		
		
			test (1.increases#c.event_before_new3 + 1.increases#c.event_before_new2 + 1.increases#c.event_before_new1 )/3 - ( 1.increases#c.event_after_new1  + 1.increases#c.event_after_new2 + 1.increases#c.event_after_new3)/3  =0

		
		
		
		coefplot  (model2c, keep(0.increases#c.event_before_new3 0.increases#c.event_before_new2 0.increases#c.event_before_new1 ) omitted baselevels  mcolor(blue) ciopts(lcolor(blue)) msymbol(d)) ///
		 (model2c, keep(0.increases#c.event_after_new0 ) omitted baselevels mcolor(gs0) ciopts(lcolor(gso)) msymbol(d)) ///
	(model2c, keep( 0.increases#c.event_after_new1 0.increases#c.event_after_new2 0.increases#c.event_after_new3 ) omitted baselevels mcolor(red) ciopts(lcolor(red)) msymbol(d)) ///
	  , vertical relocate(0.increases#c.event_before_new3 = -2.84 0.increases#c.event_before_new2 = -1.84 0.increases#c.event_before_new1 = -0.84 0.increases#c.event_after_new0 = -0 ///
	0.increases#c.event_after_new1 =0.84  0.increases#c.event_after_new2=1.84 0.increases#c.event_after_new3=2.84 ) ///
	  legend(off) yline(0)  ///
	xtitle("Event time") xlabel(-3(1)3)  xline(0, lcolor(gs10) lpattern(dash) lwidth(vthin)) 

		
			graph export Analysis/Event_decreasesonly.png, replace
